
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>采购增加页面</title>
<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
</head>
<body>
	<form class="layui-form">
		<!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
		<div class="layui-form-item">
			<label class="layui-form-label">合同供应商:</label>
			<div class="layui-input-block">
				<select name="conId" id="conId" autocomplete="off"
					class="layui-input">
					<option value="">请选择合同</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">采购备注</label>
			<div class="layui-input-block">
				<div class="layui-input-inline">
					<input type="text" name="poRemark" id="poRemark"
						lay-verify="required" required placeholder="请输入" autocomplete="off"
						class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">采购总数量</label>
			<div class="layui-input-block">
				<div class="layui-input-inline">
					<input type="text" name="poSumnum" id="poSumnum" autocomplete="off" value="0"
						class="layui-input layui-disabled" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">采购总金额</label>
			<div class="layui-input-block">
				<div class="layui-input-inline">
					<input type="text" name="poSumprice" id="poSumprice" value="0"
						autocomplete="off" class="layui-input layui-disabled"
						readonly="readonly">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="button" class="layui-btn" lay-filter="productionAdd"
					value="保存订单" id="bcdd">
			</div>
		</div>
	</form>
	<script type="text/javascript" src="../../res/js/base.js"></script>
	<script type="text/javascript" src="../../res/mln/getUrlParam.js"></script>
	<script type="text/javascript" src="../../res/js/jquery-1.10.2.js"></script>
	<script src="../../layui/layui.js"></script>

	<script>
		layui.use([ 'form', 'laydate', 'laypage', 'layer', 'table', 'upload',
				'element' ], function() {
			var laydate = layui.laydate //日期
			, laypage = layui.laypage //分页
			layer = layui.layer //弹层
			, table = layui.table //表格
			, upload = layui.upload //上传
			, element = layui.element, form = layui.form; //元素操作

			//监听Tab切换
			element.on('tab(demo)', function(data) {
				layer.msg('切换了：' + this.innerHTML);
				console.log(data);
			});

			//监听工具条
			table.on('tool(demo)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
				var data = obj.data //获得当前行数据
				, layEvent = obj.event; //获得 lay-event 对应的值

			});
			//条件查询
			var $ = layui.$;

			var url = "../../contractTableAction/findAll.action";
			$.post(url, null, function(mes) {
				for (var i = 0; i < mes.length; i++) {
					$("#conId").append(
							"<option value="+mes[i].conId+">" + mes[i].conTwo
									+ "</option>");
				}
				//form表单重新渲染
				form.render();
			});

			$('#bcdd').on('click', function() {
				var conId = document.getElementById('conId').value;
				var poRemark = $("#poRemark").val();
				var poSumnum = $("#poSumnum").val();
				var poSumprice = $("#poSumprice").val();
				if (conId == "") {
					layer.msg('请选择合同', {
						time : 1000
					});
				} else {
					var url = "../../SalesStatistics/addPurchaseOrder.action";
					var data = {"conId":conId,"poRemark":poRemark,"poSumnum":poSumnum,"poSumprice":poSumprice};
					$.ajax({
						url:url,
						data:data,
						success:function(msg){
							var rows = msg.rows;
							var poId = msg.poId;
							alert(rows);
							if(rows > 0){
								sessionStorage['numTwo'] = poId;
								layer.msg('增加成功!',{time:1000},function(){
									parent.location.reload();//刷新父页面
								});
							}else {
								sessionStorage['numOne'] = "";
								layer.msg('增加失败!',{time:1000},function(){
									parent.location.reload();//刷新父页面
								})
							}
						},
						dataType:"JSON"
					});
				}

			});
		});
	</script>

</body>
</html>